import React, { memo } from "react";
import Step2 from "./Step2";
import Step3 from "./Step3";
import Step5 from "./Step5";
import { ChatLoadText, ChatLoadMd } from "../ChatLoadDom";
import ChatOptCalculate from "../ChatOptCalculate";
import "./index.less";
import useSequentialLoader from "@/utils/hooks/useSequentialLoader";

export interface AutoModelDataType {
  optCalResult: {
    beforeAnalysisContent: string;
    list: any[];
    afterAnalysisContent: string;
  };
  targetIndexResult: {
    targetType: string;
    targetIndexList: any[];
  };
  analysisContent: string;
  analysisIndexResult: {
    bottleneckType: string;
    analysisIndexList: any[];
  };
  modelCalculateResult: any[];
  modelCalculateReportResult: string;
  createTime: string;
}

interface IProps {
  data: AutoModelDataType;
  loading: boolean;
  onRender?: (isForce?: boolean) => void;
}

const ChatAutoModelCalculate: React.FC<IProps> = ({
  data,
  loading,
  onRender,
}) => {
  // Component State
  // Component Effect
  const loadedComponents = useSequentialLoader(
    [
      {
        component: ChatOptCalculate,
        effectKey: "optCalResult",
        // skipFn: (originData: any) => {
        //     return originData.optCalResult && Object.keys(originData.optCalResult).length === 0
        // }
      },
      {
        component: ChatLoadText,
        effectKey: "analysisContent",
      },
      {
        component: Step2,
        effectKey: "analysisIndexResult",
        effectFn: (effectData: any) => {
          return (
            effectData.analysisIndexResult &&
            Object.keys(effectData.analysisIndexResult).length !== 0
          );
        },
      },
      {
        component: Step3,
        effectKey: "modelCalculateResult",
        effectFn: (effectData: any) => {
          return (
            effectData.modelCalculateResult &&
            !!effectData.modelCalculateResult.length
          );
        },
      },
      {
        component: ChatLoadMd,
        effectKey: "modelCalculateReportResult",
      },
      {
        component: Step5,
        effectKey: "modelCalculateReportResult",
      },
    ],
    data,
    {
      onLoad: () => {
        onRender && onRender(true);
      },
      onEnd: () => {
        onRender && onRender(true);
      },
    },
    {
      loading: loading,
      autoRender: true,
    },
    {
      onRender,
    }
  );
  return <div className="chat-auto-model-calc">{loadedComponents}</div>;
};

export default memo(ChatAutoModelCalculate);
